package com.jy.adscm.operation.mscyb.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.operation.base.bean.JyCustomerProvider;
import com.jy.adscm.operation.base.bean.JyGoods;
import com.jy.adscm.operation.base.mapper.mysql.JyCustomerProviderMapper;
import com.jy.adscm.operation.base.mapper.mysql.JyGoodsMapper;
import com.jy.adscm.operation.mscyb.bean.JqcpMachineproductdetail;
import com.jy.adscm.operation.mscyb.mapper.mysql.JqcpMachineproductdetailMapper;
import com.jy.adscm.operation.mscyb.service.JqcpMachineproductdetailService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.system.mapper.mysql.JyCodeMapper;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2018-12-07
 */
@Service
public class JqcpMachineproductdetailServiceImpl extends ServiceImpl<JqcpMachineproductdetailMapper, JqcpMachineproductdetail> implements JqcpMachineproductdetailService {

  JyUserMapper jyUserMapper;
  @Autowired
    JyCustomerProviderMapper jyCustomerProviderMapper;
    private String tid;

    @Autowired
    public JqcpMachineproductdetailServiceImpl(JyUserMapper jyUserMapper) {
        this.jyUserMapper = jyUserMapper;
    }

    @Override
    public List<JqcpMachineproductdetail> selectByTid(String tid) {
        this.tid = tid;
        Wrapper<JqcpMachineproductdetail> wrapper =new EntityWrapper<>();
        wrapper.eq("TID",tid);
        List<JqcpMachineproductdetail> jqcpMachineproductdetails = super.selectList(wrapper);
        for (JqcpMachineproductdetail jqcpMachineproductdetail : jqcpMachineproductdetails) {
             if (AdscmBaseUtils.getInstance().isNotEmpty(jqcpMachineproductdetail.getCustomer(),null)){
                 JyCustomerProvider jyCustomerProvider = jyCustomerProviderMapper.selectById(jqcpMachineproductdetail.getCustomer());
                 jqcpMachineproductdetail.setCustomerName(jyCustomerProvider.getName());
             }
             if (AdscmBaseUtils.getInstance().isNotEmpty(jqcpMachineproductdetail.getPerson(),null)){
                 JyUser jyUser = jyUserMapper.selectById(jqcpMachineproductdetail.getPerson());
                 jqcpMachineproductdetail.setPersonName(jyUser.getName());
             }

        }
        return jqcpMachineproductdetails;
    }

    @Override
    public List<JyCustomerProvider> queryCustomer() {
        Wrapper<JyCustomerProvider> wrapper = new EntityWrapper<>();
        wrapper.setSqlSelect("ID","NAME");
        wrapper.eq("TYPE",1);
        List<JyCustomerProvider> jyCustomerProviders = jyCustomerProviderMapper.selectList(wrapper);
        return jyCustomerProviders;
    }
}
